from ursina import *
import random
app = Ursina()
# window.title = '摘苹果'
# window.vsync = 30
window.fullscreen = False
def input(key):
    if key == "q":
        quit()
def update():
    global apple_dy, basket_dx, score
    apple.y += time.dt * apple_dy
    basket.x += held_keys["right arrow"] * time.dt * basket_dx
    basket.x -= held_keys["left arrow"] * time.dt * basket_dx
    hit_info = apple.intersects()
    if hit_info.hit:
        apple.x = random.randint(-4,4)
        apple.y = 4
        score += 1
        print_on_screen(f"scores:{score}",position=(-0.8,0.45),scale=1,duration=3)
    if apple.y < -4:
        print_on_screen("Game Over",position=(0,0),origin=(0,0),scale=2,duration=3)

        apple.x = random.randint(-4,4)
        apple.y = 10

left_wall = Entity(model="quad",color=color.gray,scale=(0.6,10),position=(-7,0,0))
right_wall = duplicate(left_wall,x =7)
apple = Entity(model="quad",texture="img/apple.png",position=(random.randint(-4,4),10),collider="box")
basket = Entity(model="quad",texture="img/people.png",position=(0,-3),collider = "box")
apple_dy = -2
basket_dx = 5
score = 0
app.run()